//
//  DLTreesTest.cpp
//  
//
//  Created by Louis CHU on 19/09/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#include "DLTreesTest.h"
#include "DLTrees.h"

#include <iostream>

using namespace std;

using namespace dlab::core;

//void print (CBalancedBinarySearchTreeNode<int> * tree)
//{
//    if (tree == 0)
//    {
//        cout<<"NIL";
//    }
//    else
//    {
//        cout<<"Node "<<tree->getElement()<<" :size "<<tree->getSize();
//        print(tree->getLeft());
//        print(tree->getRight());
//    }
//   
//}


void print (CBinaryTreeNode<int> * tree)
{
    if (tree == 0)
    {
        cout<<"NIL";
    }
    else
    {
        cout<<"Node "<<tree->getValue()<<" :size "<<tree->getSize();
        print(tree->getLeft());
        print(tree->getRight());
    }
    
   }


void CTreesTest::testBalancedBinaryTree()
{

    //int tab[] = { 11, 13, 4, 7, 1, 9, 55, 67, 8, 24, 100 , 75, 19, 23, 6};
    int tab[] = { 1, 13, 14, 17, 21, 9, 55, 67, 8, 24, 100 , 75, 19, 23, 6};
    
//    CBalancedBinarySearchTreeNode<int> * balancedTree = new CBalancedBinarySearchTreeNode<int>(10);
//    print(balancedTree);
//    
//    if (!balancedTree->getLeft()) {
//        cout<<"toto";
//    }
//        
//    for (int i = 0; i< 15; i++) 
//    {
//        balancedTree->insert(tab[i]);
//    }
//    
//    print(balancedTree);

    CBinaryTreeNode<int> *  balancedTree = new CBalancedBinarySearchTreeNode<int>(10);
    
    for (int i = 0; i< 15; i++) 
    {
        balancedTree->insert(tab[i]);
    }
    print(balancedTree);
    
    INode<int> * itNode = balancedTree;
    while (itNode) {
        
        cout<<"value "<<itNode->getValue()<< "\n";
        
        itNode = itNode->getNext();
    }
    cout<<"-------------\n";

    itNode  = balancedTree->getLast();
    while (itNode) {
        cout<<"value "<<itNode->getValue()<< "\n";

        itNode = itNode->getPrevious();
    }

}



